var app = getApp()
var wxParse = require('../../../templates/wxParse/wxParse.js');
var getAppGlobalData = require('../../../templates/copyright/copyright.js');
Page({
  data: {
    id: '',
    type: '',
    name: '',
    table_name: '',
    globalData: {},
    detailData: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    console.log(this);
    var that = this; 
    getAppGlobalData.getAppGlobalData(that);
    if (options) {
      wx.setNavigationBarTitle({
        title: options.name
      })
      that.setData({
        id: options.id,
        type: options.type,
        name: options.name,
        table_name: options.table_name
      })
    }

    if (options.to_uid) {
      app.globalData.to_uid = that.data.to_uid;
    } 
    if (options.from_id) {
      app.globalData.from_id = that.data.from_id;
    }

    if(wx.getStorageSync("formID")){
      let formID = wx.getStorageSync("formID");
      formID = that.data.from_id;
      wx.setStorageSync("formID", formID);
    } else{
      wx.setStorageSync("formID", that.data.from_id);
    }
 
    that.getDetailData();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  onPullDownRefresh: function () {
    // 监听用户下拉动作
  },
  onReachBottom: function () {
    // 页面上拉触底
  },
  onShareAppMessage: function (res) {
    // 用户点击右上角分_享
    var that = this;
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
    }
    else {
      console.log("来自右上角转发菜单")
    }
    return {
      title: '',
      path: '/longbing_card/pages/company/detail/detail?to_uid=' + app.globalData.to_uid + '&from_id=' + wx.getStorageSync("userid") + '&id=' + that.data.id + '&type=' + that.data.type + '&name=' + that.data.name + '&table_name=' + that.data.table_name,
      imageUrl: ''
    };
  },
  getDetailData: function () {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/modularInfo',
      'cachetime': '30',
      'method': 'POST',
      'data': {
        id: that.data.id,
        table_name: that.data.table_name
      },
      success: function (res) {
        console.log("entry/wxapp/modularInfo ==>", res)
        if (!res.data.errno) {
          wxParse.wxParse('content', 'html', res.data.data.content, that, 5);
          var date = new app.util.date();
          res.data.data.create_time = date.dateToStr('MM月DD日', date.longToDate(res.data.data.create_time * 1000));
          that.setData({
            detailData: res.data.data
          })
        }
      },
      fail: function (res) {
        console.log("fail ==> ",res)
      }
    })
  },
  toJump: function (e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    var content = e.currentTarget.dataset.content;
    if (status == 'toCall') {
      console.log("联系HR")
      if (!content) {
        return false;
      } else {
        wx.makePhoneCall({
          phoneNumber: content
        });
      }
    }
  }
})